﻿//-----------------------------------------------------------------------
// <copyright file="ThemeManager.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 

namespace ChatBox.UI.Themes
{
    using System;
    using System.Collections.Generic;
    using System.Windows;

    /// <summary>
    /// manager for xaml resource themese
    /// </summary>
    public class ThemeManager
    {
        /// <summary>
        /// The themes that can be used
        /// </summary>
        private readonly List<string> themes = new List<string>
          {
                  "Blue", 
                  "Red", 
                  "Green", 
                  "Black", 
                  "White", 
                  "DarkGrey", 
                  "Fade"
          };

        /// <summary>
        /// The theme that is currently in use
        /// </summary>
        private string currentTheme;

        /// <summary>
        /// Gets the list of themes that can be used
        /// </summary>
        public IEnumerable<string> Themes
        {
            get
            {
                return this.themes;
            }
        }

        /// <summary>
        /// Gets or sets the theme that is currently in use
        /// </summary>
        public string CurrentTheme
        {
            get
            {
                return this.currentTheme;
            }

            set
            {
                if (this.currentTheme != value)
                {
                    this.currentTheme = value;
                    this.SetCurrentTheme(value);
                }
            }
        }

        /// <summary>
        /// Set the UI theme
        /// </summary>
        /// <param name="themeName">the name of the theme</param>
        private void SetCurrentTheme(string themeName)
        {
            if (! this.themes.Contains(themeName))
            {
                throw new ArgumentException("theme not found", "themeName");
            }

            Application.Current.Resources.MergedDictionaries.Clear();
            Uri themeSource = new Uri("Themes\\" + themeName + ".xaml", UriKind.RelativeOrAbsolute);
            var resources = new ResourceDictionary();
            resources.Source = themeSource;
            Application.Current.Resources.MergedDictionaries.Add(resources);
        }
    }
}
